#include <iostream>
#include <cstdlib>

using namespace std;

void binarySearch(int a[],int begin, int end,int search);

void print(int a[],size_t size)
{
	int i;
	for(i=0;i<size;++i)
	{
		cout << a[i] <<endl;	
	}	
	cout <<endl;
}

int comparer(const void* a, const void* b)
{
	return (*(int*)a-*(int*)b);	
}

int main(int argc,char* agrv[])
{
	int a[]={1,5,3,2,20,34,35,24,12,28};
	int b;
	qsort(a,10,sizeof(a[0]),comparer);
	print(a,10);
	cin>>b;
	
	binarySearch(a,0,9,b);
	system("pause");
	return 0;
}

void binarySearch(int a[],int begin, int end,int search)
{
	if(begin>end)
	{
		cout << "No result!" <<endl;
		return;
	}
	
	int temp = a[(begin+end)/2];
	if(search<temp)
	{
		binarySearch(a,begin,(begin+end)/2-1,search);	
	}
	else if(search>temp)
	{
		binarySearch(a,(begin+end)/2+1,end,search);	
	}
	else
	{
		cout << "FIND!" << endl;	
	}
	
}
